﻿using IceCS.LinuxFilePermission.Core;
using System;

namespace IceCS.LinuxFilePermission.Cmd
{
    class Program
    {
        static void Main(string[] args)
        {

            var uRoot = GetRootUser();
            var uTim = GetTimUser();
            var gRoot = GetRootGroup();
            var fDoc1 = new LinuxFile()
            {
                Id = 1,
                Name = "doc1.txt",
                CreateTime = DateTime.Now,
                LastModifiedTime = DateTime.Now,
                Owner = uRoot,
                Group = gRoot,
                Path = "/1",
                IsDirectory = false
            };

            var fLog1 = new LinuxFile()
            {
                Id = 2,
                Name = "log1.log",
                CreateTime = DateTime.Now,
                LastModifiedTime = DateTime.Now,
                Owner = uTim,
                Group = gRoot,
                Path = "/2",
                IsDirectory = false
            };

            var dDir1 = new LinuxFile()
            {
                Id = 3,
                Name = "usr",
                CreateTime = DateTime.Now,
                LastModifiedTime = DateTime.Now,
                Owner = uRoot,
                Group = gRoot,
                Path = "/3",
                IsDirectory = true
            };

            var fpe = new FilePermissionEntity()
            {
                File = fDoc1
            };
            Console.WriteLine(fpe);
            Console.WriteLine(fpe.ToBinaryString());
            fpe.OtherPermission = new FilePermissionSetter(fpe.OtherPermission).Add(FilePermission.Execute).GetPermission();
            fpe.OwnerPermission = new FilePermissionSetter(fpe.OwnerPermission).Add(FilePermission.Execute).GetPermission();
            Console.WriteLine(fpe);
            Console.WriteLine(fpe.ToBinaryString());

            fpe = new FilePermissionEntity()
            {
                File = fLog1
            };
            Console.WriteLine(fpe);
            Console.WriteLine(fpe.ToBinaryString());
            fpe.OtherPermission = new FilePermissionSetter(fpe.OtherPermission).Add(FilePermission.Execute).GetPermission();
            Console.WriteLine(fpe);
            Console.WriteLine(fpe.ToBinaryString());

            fpe = new FilePermissionEntity()
            {
                File = dDir1
            };
            Console.WriteLine(fpe);
            Console.WriteLine(fpe.ToBinaryString());
            fpe.OtherPermission = new FilePermissionSetter(fpe.OtherPermission).Add(FilePermission.Execute).GetPermission();
            Console.WriteLine(fpe);
            Console.WriteLine(fpe.ToBinaryString());
        }

        private static User GetRootUser()
        {
            return new User()
            {
                Id = "001",
                Name = "root"
            };
        }

        private static User GetTimUser()
        {
            return new User()
            {
                Id = "002",
                Name = "tim"
            };
        }

        private static Group GetRootGroup()
        {
            return new Group()
            {
                Id = "001",
                Name = "root"
            };
        }
    }
}
